package com.wang.designpattern.responsibilitychain;

import com.alibaba.fastjson.JSONObject;
import com.wang.designpattern.responsibilitychain.domain.AttendanceClockDO;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Client {
    public static void main(String[] args) {

        String str = "{\n" +
                "\t\"empCode\":\"E000111\",\n" +
                "\t\"empName\":\"测试员工01\",\n" +
                "\t\"orgCode\":\"08001\",\n" +
                "\t\"orgName\":\"测试组织01\",\n" +
                "\t\"clockDate\":\"2021-11-02\",\n" +
                "\t\"amSetStartTime\":\"09:00\",\n" +
                "\t\"amSetEndTime\":\"12:00\",\n" +
                "\t\"pmSetStartTime\":\"14:00\",\n" +
                "\t\"pmSetEndTime\":\"18:00\",\n" +

                "\t\"amStartTime\":\"08:40\",\n" +
                "\t\"amEndTime\":\"12:40\",\n" +
                "\t\"pmStartTime\":\"13:20\",\n" +
                "\t\"pmEndTime\":\"18:29\"\n" +
                "}";
        JSONObject jsonObject = JSONObject.parseObject(str);
        AttendanceClockDO attendanceClockDO = jsonObject.toJavaObject(AttendanceClockDO.class);
        // 类型		打卡结果数据
        Map<String, AttendanceClockDO> clockResultDataMap = new HashMap<>();

        AmAbsentAttendanceHandler amAbsentAttendanceHandler = new AmAbsentAttendanceHandler("旷工处理类-上午");
        PmAbsentAttendanceHandler pmAbsentAttendanceHandler = new PmAbsentAttendanceHandler("旷工处理类-下午");
        AmLateAttendanceHandler amLateAttendanceHandler = new AmLateAttendanceHandler("迟到处理类-上午");
        PmLateAttendanceHandler pmLateAttendanceHandler = new PmLateAttendanceHandler("迟到处理类-下午");
        AmLeaveEarlyAttendanceHandler amLeaveEarlyAttendanceHandler = new AmLeaveEarlyAttendanceHandler("早退处理类-上午");
        PmLeaveEarlyAttendanceHandler pmLeaveEarlyAttendanceHandler = new PmLeaveEarlyAttendanceHandler("早退处理类-下午");

        amAbsentAttendanceHandler.setHandler(pmAbsentAttendanceHandler);
        pmAbsentAttendanceHandler.setHandler(amLateAttendanceHandler);
        amLateAttendanceHandler.setHandler(pmLateAttendanceHandler);
        pmLateAttendanceHandler.setHandler(amLeaveEarlyAttendanceHandler);
        amLeaveEarlyAttendanceHandler.setHandler(pmLeaveEarlyAttendanceHandler);

        amAbsentAttendanceHandler.processRequest(clockResultDataMap, attendanceClockDO);

        String result = JSONObject.toJSONString(clockResultDataMap);

        System.out.println(result);

        // 待插入结果
        List<AttendanceClockDO> attendanceClockDOList = new ArrayList<>();
        if (0 == clockResultDataMap.size()) {
            attendanceClockDOList.add(attendanceClockDO);
        } else {
            attendanceClockDOList.addAll(clockResultDataMap.values());
        }

        String attendanceClockDOListStr = JSONObject.toJSONString(attendanceClockDOList);

        System.out.println(attendanceClockDOListStr);
    }
}
